package com.funever.activity;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentTransaction;
import com.actionbarsherlock.view.ActionMode;
import com.funever.combworkalerm.R;
import com.funever.fragment.BaseFragment;
import com.funever.fragment.MenuFragment;
import com.funever.fragment.TypeReviewFragment;
import com.funever.utils.Utils;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

public class MainActivity extends SlidingFragmentActivity {
	
	BaseFragment mContent;
	
	ActionMode mMode;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitle("Main");
		setTheme(R.style.ActionBar);
		setContentView(R.layout.content_frame);
		setBehindContentView(R.layout.menu_frame);
		
		getSupportActionBar().setDisplayHomeAsUpEnabled(false);
//		getSupportActionBar().setDisplayShowTitleEnabled(false);
		getSupportActionBar().setDisplayUseLogoEnabled(false);
		getSupportActionBar().setDisplayShowHomeEnabled(false);
		getSlidingMenu().setSlidingEnabled(true);
		getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		
		/**
		 * 设置菜单的一些属性
		 */
		SlidingMenu sm = getSlidingMenu();
		sm.setBehindOffset(Utils.dip2px(this, 200));
		sm.setShadowWidth(25);
		sm.setShadowDrawable(R.drawable.shadow);
		sm.setBehindScrollScale(0.05f);
		sm.setFadeDegree(0.5f);
		
		if(mContent == null){
			mContent = new TypeReviewFragment();
		}
		
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		
		ft.replace(R.id.content_frame, mContent);
		ft.replace(R.id.menu_frame, new MenuFragment());
		
		ft.commit();
	}
	
	public void switchFragment(BaseFragment fragment){
		mContent = fragment;
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		//替换中间fragment
		ft.replace(R.id.content_frame, mContent);
		ft.commit();
		/**
		 * 50ms后显示
		 */
		Handler h = new Handler();
		h.postDelayed(new Runnable() {
			public void run() {
				getSlidingMenu().showContent();
			}
		}, 50);
	}
	
}
